package com.yanqu.road.server.cmd.activity.fanxiuspring;

import com.yanqu.road.entity.activity.fanxiuspring.FanXiuSpringConfig;
import com.yanqu.road.entity.activity.fanxiuspring.UserFanXiuSpringData;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.FanxiuspringProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.fanxiuspring.FanXiuSpringModule;
import com.yanqu.road.server.gameplayer.module.activity.fanxiuspring.FanXiuSpringPb;
import com.yanqu.road.server.manger.activity.ActivityMgr;
import com.yanqu.road.server.manger.activity.fanxiuspring.FanXiuSpringMgr;
import com.yanqu.road.server.protocol.Protocol;

import java.util.Map;

@Cmd(code = Protocol.S_FAN_XIU_SPRING_GET_USER_DATA, desc = "获取玩家数据")
public class FanXiuSpringGetUserDataCmd extends AbstractCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {

        FanxiuspringProto.FanXiuSpringGetUserDataRespMsg.Builder syncMsg = FanxiuspringProto.FanXiuSpringGetUserDataRespMsg.newBuilder();
        syncMsg.setRet(0);
        Map<Integer, UserFanXiuSpringData> userDataMap = player.getModule(FanXiuSpringModule.class).getUserDataMap();
        for (Map.Entry<Integer, FanXiuSpringConfig> entry : FanXiuSpringMgr.getConfigMap().entrySet()) {

            FanXiuSpringConfig config = entry.getValue();

            if (!ActivityMgr.activityInShowTime(config.getActivityInfo())) {
                continue;
            }

            UserFanXiuSpringData userData = userDataMap.get(config.getActivityInfo().getActivityId());
            if(userData == null){
                continue;
            }

            FanxiuspringProto.FanXiuSpringUserDataTemp.Builder builder = FanXiuSpringPb.buildUserData(userData);
            builder.setChildType(config.getActivityInfo().getChildType());
            syncMsg.addUserData(builder);
        }

        player.sendPacket(Protocol.U_FAN_XIU_SPRING_GET_USER_DATA, syncMsg);
    }

    @Override
    public void sendData(GamePlayer player) {

    }
}
